package Exercise;

import java.util.Arrays;

/**
 * Description：
 * Author: zhangc
 * Date：2017/8/29 19:51
 */
public class QuickSort {
    public static <T extends Comparable<? super T>> void quickSort(T[] arr, int low, int high) {
        if (low >= high)
            return;
        int start = low, end = high;
        T temp = arr[ start ];
        while (start < end) {
            while (start < end && arr[ end ].compareTo(temp) > 0)
                end--;
            if (start < end)
                arr[ start++ ] = arr[ end ];
            while (start < end && arr[ start ].compareTo(temp) < 0)
                start++;
            if (start < end)
                arr[ end-- ] = arr[ start ];
        }
        arr[ start ] = temp;
        quickSort(arr, low, start - 1);
        quickSort(arr, start + 1, high);
    }

    public static void main(String[] args) {
        Integer[] arr = {1, 3, 5, 4, 8, 2, 6};
        quickSort(arr, 0, arr.length - 1);
        System.out.println(Arrays.toString(arr));
    }
}
